﻿      function Trim(cadena)
        {
            return $.trim(cadena);
        }

        function ValidarCaja(obj, expreg, message, empty, length, lengthmax) {
            var texto = Trim($(obj).val());
            if (empty == false) {
                var father = $(obj).parent();
                father.children('.ErrorRequiere').remove();
                father.children('br').remove();

                if (texto!='') 
                {                 
                    if (texto.match(expreg) == null) 
                    {
                        father.append('<br/><span class="ErrorRequiere">' + message + '</span>');
                       
                        cont += 1
                    }
                    else if (length == true) 
                    {
                        if (texto.length>lengthmax || texto.length<lengthmax) {
                            father.append('<br/><span class="ErrorRequiere">Se requiere ' + lengthmax + ' caracteres</span>');
                        	
                            cont += 1                        
                        }
                    }               
                }     
            }
            else if(empty==true){
                var father = $(obj).parent();
                father.children('.ErrorRequiere').remove();
                father.children('br').remove();
                if (texto=='') {
                    father.append('<br/><span class="ErrorRequiere"> Se requiere este valor</span>');
                    cont += 1
                }
                else if (texto.match(expreg) == null) {
                    father.append('<br/><span class="ErrorRequiere">' + message + '</span>');
                    cont += 1
                }
                else if (length == true) {
                    if (texto.length > lengthmax || texto.length < lengthmax) {
                        father.append('<br/><span class="ErrorRequiere">Se requiere ' + lengthmax + ' caracteres</span>');
                        cont += 1
                    }
                }                            
            }
        }

        function ValidarLista(obj, message) {      
            var father = $(obj).parent();
            father.children('.ErrorRequiere').remove();
            father.children('br').remove();
            //alert($(obj + ' option:selected').attr('value'))
            if ($(obj + ' option:selected').attr('value') == "" || $(obj + ' option:selected').attr('value') == "0") {
                father.append('<br><span class="ErrorRequiere"> '+ message +' </span>');
                cont+= 1;
            }else if($(obj).attr('value') == "" || $(obj).attr('value') == "0")
            {
                father.append('<br><span class="ErrorRequiere"> '+ message +' </span>');
                cont+= 1;            
            }
        }
        function CompareLista(obj1, obj2, message, type) {
            if ($(obj1 + ' option:selected').attr('value') != '' && $(obj2 + ' option:selected').attr('value') != '')
            {
                var father = $(obj2).parent();
                father.children('.ErrorRequiere').remove();
                father.children('br').remove();
                if (type == 'different') {
                    if ($(obj1 + ' option:selected').attr('value') == $(obj2 + ' option:selected').attr('value')) {
                        father.append('<br><span class="ErrorRequiere"> ' + message + ' </span>');
                        cont += 1;                    
                    }
                }            
            }

        }
        function ValidarListText(obj,message)
        {
                var father = $(obj).parent();
                father.children('.ErrorRequiere').remove();
                father.children('br').remove();               
                if ($(obj +' option').length<1) {
                        father.append('<br><span class="ErrorRequiere">' + message +'</span>');                       
                        cont += 1;  
                }              
        }
        function ClearMessage(obj) {
            var father = $(obj).parent();
            father.children('.ErrorRequiere').remove();
            father.children('br').remove();
        }
        function ValorError(obj,valor) {
            var texto=Trim($(obj).val());
            var father = $(obj).parent();
            father.children('.ErrorRequiere').remove();
            father.children('br').remove();
            var condicion = true;            
            if (texto== valor)
            { condicion = false; father.append('<br><span class="ErrorRequiere"> El valor ingresado no esta permitido</span>'); } else { condicion = true; }
            return condicion;            
        }
        
        var cont = 0;
        var exprregletras = "^[ a-zA-ZñÑáéíóúÁÉÍÓÚ]+$";
        var exprregnumeros = "^[0-9]+$";
        var exprregbrevete = "^[A-ZÑ]{1,10}\[0-9]{1,10}$";
        var exprregprecios2 = "^[0-9]+[.]{1,1}\[0-9]{2,2}$";
        var exprregalfanumericos = "^[ a-zA-ZñÑ0-9áéíóúÁÉÍÓÚ]+$";
        var exprregnombres = "^[A-ZÑa-zñ' ]+$";
        var exprregrz = "^[0-9A-ZÑa-zñ&' ]+$";        
        //var exprregmail = "^[0-9A-Za-zñÑ-_.]{1,50}\[@]{1,1}\[0-9A-Za-zñÑ-_.]{1,100}\[.]{1,1}\[a-z]{1,6}";
        //var exprregmail="^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]=))$";
        var exprregmail="^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$";
        var exprretelefononac = "^[0-9]{1,2}\[-]{1,1}\[0-9]+$";
        var exprretelefonoext = "^[0-9]{1,2}\[-]{1,1}\[0-9]{1,2}\[-]{1,1}\[0-9]+$";
        var exprredireccion = "^[ 0-9a-zA-ZñÑáéíóúÁÉÍÓÚ./°-]+$";
        var exprrehorarisinmer = "^[0-9]{2,2}\[:]{1,1}\[0-9]{2,2}$";
        var exprrefecha = "^[0-9]{2,2}\[/]{1,1}\[0-9]{2,2}\[/]{1,1}\[0-9]{4,4}$";
        var exprrehora = "^[0-9]{2,2}\[:]{1,1}\[0-9]{2,2}\[A,P,M]{2,2}$";
        var exprreplaca = "^[0-9A-ZÑ]{2,4}\[-]{1,1}\[0-9A-ZÑ]{2,6}$";
        
        var messageletras = "Solo se permite caracteres alfabeticos";
        var messagenumeros = "Solo se permite caracteres numericos";
        var messagebrevete = "El formato de brevete debe ser alfanumerico";
        var messageprecios2 = "Formato de precio no valido (2.00)";
        var messagealfanumericos = "Solo se permite caracteres alfanumericos";
        var messagenombres = "Solo se permite caracteres alfabeticos y apostrofes";
        var messagerz = "Solo se permite caracteres alfanumericos y apostrofes";
        
        var messagemail = "El formato de email ingresado no es correcto";
        var messagetelefononac = "El formato de telefono debe ser:(01-2870973)";
        var messagetelefonoext = "El formato de telefono debe ser:(51-01-2870973)";
        var messagedireccion = "Solo se permite caracteres alfanumericos <br>y algunos caracteres especiales";
        var messagehorarisinmer = "El formato de hora debe ser:(00:00)";  
        var messagefecha = "El formato de fecha debe ser:(01/01/2000)";  
        var messagehora = "El formato de hora debe ser:(12:00PM ó 12:00AM)";  
        var messageplaca = "El formato correcto es XXX-XXXX";  
        
              